<template>
	<view class="">
		<web-view v-if="h5Url" :src="h5Url" 
			:webview-styles="webviewStyles"
			 @message="getMessage"
		></web-view>
		<view v-if="failTitle"
		class="bg-white text-center" 
		style="position:absolute;width: 100%;height: 100%;left: 0;top: 0;">
			<view  style="width:100%;height:20%;"></view>
			<view class="text-bold text-lg text-black">
				抱歉，没有找到您请求的页面
			</view>
		</view>
	</view>
</template>

<script>
let titleTimer, errTimer;
export default {
    data() {
        return {
			webviewStyles: {
				progress: {
					color: '#FF3333'
				}
			},
            h5Url: '',
			failTitle: false
        }
    },
    onLoad (options) {
		if (options && options.url) {
			this.h5Url = decodeURIComponent(options.url)
			console.log(this.h5Url);
		}
		if (options && options.title) {
			titleTimer = setTimeout(() => {
				uni.setNavigationBarTitle({
					title: options.title
				})
			}, 800)
			titleTimer = setTimeout(() => {
				this.failTitle = true
			}, 3000)
		}
		
    },
	onUnload() {  
	    if(titleTimer) {
			clearTimeout(titleTimer);
			titleTimer = null;
	    }
	    if(errTimer) {
			clearTimeout(errTimer);
			errTimer = null;
	    }  
	},
	methods: {
		getMessage(e) {
			uni.showModal({
				content: JSON.stringify(e.detail),
				showCancel: false
			})
		}
	}

}
</script>